const axios = require("axios");
const cheerio = require("cheerio");
// 获取游侠游戏排行数据入口
async function getYouXiaRanking() {
  const res = await axios.get("https://www.ali213.net/paihb.html");
  return parsePageGameRanking(res.data);
}
// 获取游戏排行榜数据
function parsePageGameRanking(page) {
  const $ = cheerio.load(page);
  let allDataList = [];
  $(".yycont_lst .gsPlay_cont").each(function () {
    let currentList = [];
    $(".lst_cont", this).each(function () {
      const item = {};
      item.name = $(".detail_cont a", this).attr("title");
      item.link = $(".detail_cont a", this).attr("href");
      item.img = $(".detail_cont a img", this).attr("src");
      if (currentList.length < 20) currentList.push(item);
    });
    allDataList.push(currentList);
  });
  return allDataList;
}

module.exports = getYouXiaRanking;
